// 交通区块类，用于管理物资和人员运输
class TransportBlock {
    constructor(starting, destination) {
        this.remainDay = 0; // 剩余天数
        this.destination = destination; // 目的地城市
        
        // 各种物资和人员
        this.livingMaterial = 0;
        this.protectiveMaterial = 0;
        this.medicalMaterial = 0;
        this.newsNum = 0;
        this.medicalNum = 0;
        this.securityNum = 0;
        this.trafficNum = 0;
        this.researchNum = 0;
        
        // 计算运输时间
        const rank = starting.getDistRank(destination);
        this.remainDay = Math.ceil((rank / starting.spreadRange) + 1);
    }

    // 更新运输状态
    update() {
        if (this.remainDay > 0) {
            this.remainDay--;
            return false;
        } else {
            this.inputBlock();
            return true; // 运输完成
        }
    }

    // 获取总人数
    getTotal() {
        return this.newsNum + this.medicalNum + this.securityNum + this.trafficNum + this.researchNum;
    }

    // 将物资和人员输入到目的地城市
    inputBlock() {
        // 增加人员
        this.destination.newsNum.add(this.newsNum);
        this.destination.medicalNum.add(this.medicalNum);
        this.destination.trafficNum.add(this.trafficNum);
        this.destination.researchNum.add(this.researchNum);
        this.destination.securityNum.add(this.securityNum);
        
        // 增加物资
        this.destination.livingMaterial.add(this.livingMaterial);
        this.destination.medicalMaterial.add(this.medicalMaterial);
        this.destination.protectiveMaterial.add(this.protectiveMaterial);
        
        // 增加总人口
        this.destination.lifeBlock.addTotal(this.getTotal());
    }
}

export { TransportBlock };
